#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <set>
using namespace std;
class Solution {
public:
    bool isHappy(int n)
    {
        set<int> s;
        s.insert(n);
        while (n != 1)
        {
            int NewN = 0;
            int tmp = 10;
            while (n > 0)
            {
                cout << n << " ";
                NewN += ((n % tmp) * (n % tmp));
                n /= tmp;
            }
            cout << "(" << NewN << ")" << endl;
            cout << "----" << endl;
            n = NewN;
            if (s.find(n) != s.end())
            {
                return false;
            }
            s.insert(n);
        }
        return true;
    }
};